<?php
	function get_site_pages()
	{
		global $connection;
		$languageID = $_SESSION["language"]["id"];
		$query = "SELECT spd.*, sp.page_slug, sp.id AS id, sp.visible_in_sitemap FROM site_pages sp, site_page_details spd 
					WHERE sp.id = spd.site_page_id AND spd.language_id = ? ORDER BY spd.name";
		
		$pages = $connection->fetch_result($query, array($languageID));
		
		$site_pages = array();
		$siteURL = site_url();
		foreach ($pages as $key => $value) 
		{
			$value["url"] = $siteURL.$value["url"];
			
			if($value["page_slug"] != "events" && $value["page_slug"] != "companies" && $value["page_slug"] != "profile")
			{
				$value["url"] .= ".html";
			}
			else
			{
				$value["url"] .= "/";
			}
			
			$site_pages[$value["page_slug"]] = $value;
		}
		
		return $site_pages;	
	}
	
	function get_site_page_by_slug($url, $languageID)
	{
		global $connection;
		
		$page = $connection->fetch_one("SELECT spd.*, sp.page_slug, sp.id AS id FROM site_pages sp
												LEFT JOIN site_page_details spd ON  sp.id = spd.site_page_id
										WHERE sp.page_slug = ? AND  spd.language_id = ?", array($url, $languageID));
		
		return $page;
	}
	
	function get_site_page($url, $languageID)
	{
		global $connection;
		
		$page = $connection->fetch_one("SELECT spd.*,sp.page_slug,sp.id AS id FROM site_pages sp
												LEFT JOIN site_page_details spd ON  sp.id = spd.site_page_id
										WHERE spd.url = ? AND  spd.language_id = ?", array($url, $languageID));
		$page["images"] = get_page_images($page["id"]);
		
		return $page;
	}
	
	function get_page_images($pageID)
	{
		global $connection;
		
		$photos = $connection->fetch_result("SELECT pf.title, pf.name, pf.thumb_name FROM site_page_pictures sp
												LEFT JOIN picture_files pf ON sp.picture_id = pf.id
												WHERE sp.site_page_id = ?", array($pageID));
		return $photos;
	}
	
	function get_carousel($languageID)
	{
		global $connection;
		
		$carousel = $connection->fetch_result("SELECT cd.*, c.picture FROM carousel c
												LEFT JOIN carousel_details cd ON cd.carousel_id = c.id
												WHERE cd.language_id = ?", array($languageID));
		return $carousel;
		
	}
	
?>